package slxy.jiangtao.dts.core.common.hibernate.qbc;

import java.util.List;

@SuppressWarnings("unchecked")
public class Page {

    /**
     * 当前页数
     */
    private int currPage;

    /**
     * 每页数据条数
     */
    private int pageSize;

    /**
     * 总数据条数
     */
    private int total;

    /**总页数*/
    private int pages;

    /**当前页条数*/
    private int size;

    /**
     * 数据集
     */
    private List rows;

    public Page(List rows){
        this.rows=rows;
    }

    public Page(List rows, int pageSize, int currPage, int total) {
        this.currPage = currPage;
        this.pageSize = pageSize;
        this.rows = rows;
        this.total = total;
    }

    public <T> List<T> getRows() {
        return rows;
    }

    public void setRows(List rows) {
        this.rows = rows;
    }


    public int getTotal() {
        return total;
    }

    public int getCurrPage() {
        return currPage;
    }

    public void setCurrPage(int currPage) {
        if(currPage<1){
            currPage=1;
        }
        if(currPage>pages){
            currPage=pages;
        }
        this.currPage = currPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPages() {
        return (int)Math.ceil((double)total/pageSize);
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getSize() {
        return rows.size();
    }

    public void setSize(int size) {
        this.size = rows.size();
    }
}
